﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ReporterEngine
{
    public partial class sQuery : IEnumerable<sQuery>
    {
        public CIFModel _model;

        public List<XElement> Elements = new List<XElement>();

        public List<string> Values = new List<string>();

        private sQuery _parent;

        public bool HasError
        {
            get { return ErrorMessage.ToString().Length > 0; }
        }

        public StringBuilder ErrorMessage = new StringBuilder();

        public sQuery Parent
        {
            get { return _parent; }
        }

        public sQuery(sQuery parent)
        {
            if(parent != null)
                _model = parent._model;

            _parent = parent;
        }

        public bool IsRoot;

        public string Value
        {
            get
            {
                if (Values.Count > 0)
                    return Values[0];

                return "";
            }
        }

        public XElement Element
        {
            get { return Elements[0]; }
        }

        public string GetValue()
        {
            return null;
        }
        public sQuery New()
        {
            var result = new sQuery(this);

            return result;
        }

        public sQuery NewFromElement(XElement element)
        {
            var result = new sQuery(this);
            result.Elements.Add(element);

            return result;
        }

        public static sQuery New(CIFModel model)
        {
            var squery = new sQuery(null);
            squery._model = model;

            return squery;
        }

        public IEnumerator<sQuery> GetEnumerator()
        {
            //return Data.GetEnumerator();
            return null;
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            //return Data.GetEnumerator();
            return null;
        }
    }
}
